﻿using System;
using System.Data;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Globalization;
using System.Web.UI.HtmlControls;
using Telerik.Web.UI;
using KPIS.GERP.GHRMS.BLL;
using KPIS.GERP.GHRMS.IBLL;
using KPIS.GERP.GHRMS.MODEL;

namespace KPIS.GERP.GHRMS.APP.App_UI.UserControls
{
    public partial class PS_HisSalaryInfo : System.Web.UI.UserControl
    {
        private IHisSalaryBLL hisBLL = new HisSalaryBLL();
        private SsMng ssMng = new SsMng();
        protected void Page_Load(object sender, EventArgs e)
        {

		}
		protected bool IsUserControlPostBack
		{
			get
			{
				return this.ViewState["IsUserControlPostBack"] != null;
			}
		}
		protected override void OnLoad(System.EventArgs e)
		{
			base.OnLoad(e);

			if (!IsUserControlPostBack)
			{
				this.ViewState.Add("IsUserControlPostBack", true);

				if (Request.QueryString["sta"] != null)
					this.lblSta.Text = Request.QueryString["sta"].ToString();

				lblEmpSeq.Text = Session["emp_seq"].ToString();
				LoadDataGrid();
			}
		}
		public void LoadDataGrid()
		{
			//Thread.CurrentThread.CurrentCulture = new CultureInfo("th-TH");
			DataTable dt = hisBLL.LoadHisSalary((int?) null, Int32.Parse(lblEmpSeq.Text)).Tables[0];

			RadGrid1.DataSource = dt;
			RadGrid1.DataBind();
		}

		protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e)
		{
			if (e.CommandName == "Delete")
			{
			    int seq = Convert.ToInt32((e.Item as GridDataItem).OwnerTableView.DataKeyValues[e.Item.ItemIndex]["sal_his_seq"]);
			    hisBLL.DeleteHisSalary(seq, ssMng.UserSeqI);
			}
			LoadDataGrid();
		}

		protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
		{
			if (e.Item is GridCommandItem)
			{
				GridCommandItem commandItem = e.Item as GridCommandItem;
				LinkButton button = commandItem.FindControl("cmdAddNew") as LinkButton;

				if (button != null)
				{
					if (this.lblSta.Text == "v")
					{
						button.Enabled = false;
						button.Visible = true;
						button.Text = "";
					}
				}
			}
		}

		protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
		{
			if (this.lblSta.Text == "v")
			{
				RadGrid1.Columns[0].Visible = false;
				RadGrid1.Columns[1].Visible = false;
			}
		}
    }
}